#专门针对每一种商品设计UI界面
import tkinter as tk
from PIL import ImageTk, Image
from link import *
from parameter import *
import visitorPage as vp
from tkinter import messagebox

class air_cond():
    #空调类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('空调')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.ratio = tk.StringVar() #用作索引能效比

        self.create_page()

    def create_page(self):
        #这里得把image声明为全局变量，否则无法正常输出图片
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')

        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=100, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=100, anchor='nw')
        #tk.Button(self.page, text='确认', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select()).place(x=700, y=100, anchor='nw')

        tk.Label(self.page, text='能效比', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.ratio, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=640, y=240, anchor='nw')
        tk.Label(self.page, text='销量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=740, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=840, y=240, anchor='nw')
        tk.Label(self.page, text='能效比', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=920, y=240, anchor='nw')


    def select(self):
        obj = loginSearch()
        sql = ''

        if self.prices.get() and not self.brand.get() and not self.ratio.get():
            sql = air_cond_p(self.prices.get())
        elif not self.prices.get() and self.brand.get() and not self.ratio.get():
            sql = air_cond_b(self.brand.get())
        elif not self.prices.get() and not self.brand.get() and self.ratio.get():
            sql = air_cond_r(self.ratio.get())
        elif self.prices.get() and self.brand.get() and not self.ratio.get():
            sql = air_cond_pb(self.prices.get(), self.brand.get())
        elif self.prices.get() and not self.brand.get() and self.ratio.get():
            sql = air_cond_pr(self.prices.get(), self.ratio.get())
        elif not self.prices.get() and self.brand.get() and self.ratio.get():
            sql = air_cond_br(self.brand.get(), self.ratio.get())
        elif self.prices.get() and self.brand.get() and self.ratio.get():
            sql = air_cond_bpr(self.prices.get(), self.brand.get(), self.ratio.get())
        elif not self.prices.get() and not self.brand.get() and not self.ratio.get():
            sql = air_cond_none()

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=650, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=750, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=850, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=950, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)

        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)
        
        #购买成功后需要将库存-1，销量+1
        new_sql = update_appliances(categoryid, categoryname)
        cursor.execute(new_sql)

        obj.conn.commit()
        obj.close_conn()

class washMachine():
    #洗衣机类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('洗衣机')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.volume = tk.StringVar() #用作索引容量      
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')

        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=100, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=100, anchor='nw')
        #tk.Button(self.page, text='确认', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select()).place(x=700, y=100, anchor='nw')

        tk.Label(self.page, text='容量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.volume, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=640, y=240, anchor='nw')
        tk.Label(self.page, text='耗水量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=740, y=240, anchor='nw')
        tk.Label(self.page, text='容量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=840, y=240, anchor='nw')
        tk.Label(self.page, text='重量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=920, y=240, anchor='nw')

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get() and not self.volume.get():
            sql = washing_machine_none()
        elif self.prices.get() and not self.brand.get() and not self.volume.get():
            sql = washing_machine_p(self.prices.get())
        elif not self.prices.get() and self.brand.get() and not self.volume.get():
            sql = washing_machine_b(self.brand.get())
        elif not self.prices.get() and not self.brand.get() and self.volume.get():
            sql = washing_machine_v(self.volume.get())
        elif self.prices.get() and self.brand.get() and not self.volume.get():
            sql = washing_machine_pb(self.prices.get(), self.brand.get())
        elif self.prices.get() and not self.brand.get() and self.volume.get():
            sql = washing_machine_pv(self.prices.get(), self.volume.get())
        elif not self.prices.get() and self.brand.get() and self.volume.get():
            sql = washing_machine_bv(self.brand.get(), self.volume.get())
        elif self.prices.get() and self.brand.get() and self.volume.get():
            sql = washing_machine_pbv(self.prices.get(), self.brand.get(), self.volume.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)): 
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=650, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=750, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=850, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=950, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')

            col = col + 30

        obj.close_conn()

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)

    def purchase(self, categoryid, categoryname):
        print(categoryid, categoryname)
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)
        
        #购买成功后需要将库存-1，销量+1
        new_sql = update_appliances(categoryid, categoryname)
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()


class teleVision():
    #电视类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('电视')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.size = tk.StringVar() #用作索引屏幕尺寸    
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')

        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=100, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=100, anchor='nw')
        #tk.Button(self.page, text='确认', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select()).place(x=700, y=100, anchor='nw')

        tk.Label(self.page, text='屏幕尺寸', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=26, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.size, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=640, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=740, y=240, anchor='nw')
        tk.Label(self.page, text='屏幕尺寸', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=840, y=240, anchor='nw')
        tk.Label(self.page, text='是否联网', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=920, y=240, anchor='nw')

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get() and not self.size.get():
            sql = television_none()
        elif self.prices.get() and not self.brand.get() and not self.size.get():
            sql = television_p(self.prices.get())
        elif not self.prices.get() and self.brand.get() and not self.size.get():
            sql = television_b(self.brand.get())
        elif not self.prices.get() and not self.brand.get() and self.size.get():
            sql = television_s(self.size.get())
        elif self.prices.get() and self.brand.get() and not self.size.get():
            sql = television_pb(self.prices.get(), self.brand.get())
        elif self.prices.get() and not self.brand.get() and self.size.get():
            sql = television_ps(self.prices.get(), self.size.get())
        elif not self.prices.get() and self.brand.get() and self.size.get():
            sql = television_bs(self.brand.get(), self.size.get())
        elif self.prices.get() and self.brand.get() and self.size.get():
            sql = television_pbs(self.prices.get(), self.brand.get(), self.size.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        col = 280

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=650, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=750, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=850, y=col, anchor='nw')
            tk.Label(self.page, text='是' if data[i][4] else '否', font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=950, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')

            col = col + 30

        obj.close_conn()

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)
        
        #购买成功后需要将库存-1，销量+1
        new_sql = update_appliances(categoryid, categoryname)
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()


class heater():
    #热水器类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('热水器')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.heatmode = tk.StringVar() #用作索引加热方式    
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')

        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=100, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=100, anchor='nw')
       
        tk.Label(self.page, text='加热方式', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=26, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.heatmode, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=640, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=740, y=240, anchor='nw')
        tk.Label(self.page, text='热水产率', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=840, y=240, anchor='nw')
        tk.Label(self.page, text='加热方式', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=920, y=240, anchor='nw')

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get() and not self.heatmode.get():
            sql = heater_none()
        elif self.prices.get() and not self.brand.get() and not self.heatmode.get():
            sql = heater_p(self.prices.get())
        elif not self.prices.get() and self.brand.get() and not self.heatmode.get():
            sql = heater_b(self.brand.get())
        elif not self.prices.get() and not self.brand.get() and self.heatmode.get():
            sql = heater_h(self.heatmode.get())
        elif self.prices.get() and self.brand.get() and not self.heatmode.get():
            sql = heater_pb(self.prices.get(), self.brand.get())
        elif self.prices.get() and not self.brand.get() and self.heatmode.get():
            sql = heater_ph(self.prices.get(), self.heatmode.get())
        elif not self.prices.get() and self.brand.get() and self.heatmode.get():
            sql = heater_bh(self.brand.get(), self.heatmode.get())
        elif self.prices.get() and self.brand.get() and self.heatmode.get():
            sql = heater_pbh(self.prices.get(), self.brand.get(), self.heatmode.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=650, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=750, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=850, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=950, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)  

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)
        
        #购买成功后需要将库存-1，销量+1
        new_sql = update_appliances(categoryid, categoryname)
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()



class computer():
    #电脑类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('电脑')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=600, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=680, y=240, anchor='nw')
        tk.Label(self.page, text='CPU', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=760, y=240, anchor='nw')
        tk.Label(self.page, text='硬盘', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=860, y=240, anchor='nw')
        tk.Label(self.page, text='内存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=940, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)  

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = computer_none()
        elif self.prices.get() and not self.brand.get():
            sql = computer_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = computer_b(self.brand.get())
        else:
            sql = computer_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')
        
        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=610, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=690, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=750, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=875, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][5], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=955, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][6], j=data[i][7] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_digital(categoryid, categoryname)   
        cursor.execute(new_sql)

        obj.conn.commit()
        obj.close_conn()


class phone():
    #手机类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('手机')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=450, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=530, y=240, anchor='nw')
        tk.Label(self.page, text='CPU', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=610, y=240, anchor='nw')
        tk.Label(self.page, text='内存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=860, y=240, anchor='nw')
        tk.Label(self.page, text='像素大小', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=940, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = phone_none()
        elif self.prices.get() and not self.brand.get():
            sql = phone_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = phone_b(self.brand.get())
        else:
            sql = phone_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')
        
        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=450, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=530, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=610, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=875, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][5], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=955, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][6], j=data[i][7] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_digital(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()

class camera():
    #相机类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('相机')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=540, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=640, y=240, anchor='nw')
        tk.Label(self.page, text='像素/万', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=740, y=240, anchor='nw')
        tk.Label(self.page, text='净重/kg', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=880, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = camera_none()
        elif self.prices.get() and not self.brand.get():
            sql = camera_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = camera_b(self.brand.get())
        else:
            sql = camera_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=550, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=655, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=770, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=900, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_digital(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()



class shoes():
    #鞋类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('鞋子')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=540, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=645, y=240, anchor='nw')
        tk.Label(self.page, text='销量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=765, y=240, anchor='nw')
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=895, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = shoes_none()
        elif self.prices.get() and not self.brand.get():
            sql = shoes_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = shoes_b(self.brand.get())
        else:
            sql = shoes_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=550, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=655, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=770, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=900, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_shoes_clothes(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()

class sweater():
    #卫衣类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('卫衣')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=540, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=645, y=240, anchor='nw')
        tk.Label(self.page, text='销量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=765, y=240, anchor='nw')
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=895, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = sweater_none()
        elif self.prices.get() and not self.brand.get():
            sql = sweater_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = sweater_b(self.brand.get())
        else:
            sql = sweater_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=550, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=655, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=770, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=900, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_shoes_clothes(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()

class looseCoat():
    #外套类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('外套')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=540, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=645, y=240, anchor='nw')
        tk.Label(self.page, text='销量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=765, y=240, anchor='nw')
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=895, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = loosecoat_none()
        elif self.prices.get() and not self.brand.get():
            sql = loosecoat_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = loosecoat_b(self.brand.get())
        else:
            sql = loosecoat_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=550, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=655, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=770, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=900, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_shoes_clothes(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()

class trousers():
    #裤子类
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('裤子')
        self.window.geometry('1156x773')
        self.prices = tk.StringVar() #用作索引价格
        self.brand = tk.StringVar() #用作索引品牌
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=1156, height=773)
        self.page.pack()
        img = Image.open('megumi1.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=30, anchor='nw')
        tk.Entry(self.page, textvariable=self.prices, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=30, anchor='nw')
        tk.Button(self.page, text='返回', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=700, y=30, anchor='nw')
       
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=170, anchor='nw')
        tk.Entry(self.page, textvariable=self.brand, font=('幼圆', 25), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=170, anchor='nw')
        tk.Button(self.page, text='查询', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin', command=self.select).place(x=700, y=170, anchor='nw')

        tk.Label(self.page, text='商品名称', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=150, y=240, anchor='nw')
        tk.Label(self.page, text='价格', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=540, y=240, anchor='nw')
        tk.Label(self.page, text='库存', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=645, y=240, anchor='nw')
        tk.Label(self.page, text='销量', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=765, y=240, anchor='nw')
        tk.Label(self.page, text='品牌', font=('幼圆', 20), bg='CornflowerBlue', fg='Moccasin').place(x=895, y=240, anchor='nw')

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name) 

    def select(self):
        obj = loginSearch()
        sql = ''

        if not self.prices.get() and not self.brand.get():
            sql = trousers_none()
        elif self.prices.get() and not self.brand.get():
            sql = trousers_p(self.prices.get())
        elif not self.prices.get() and self.brand.get():
            sql = trousers_b(self.brand.get())
        else:
            sql = trousers_pb(self.prices.get(), self.brand.get())

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()
        
        self.page.destroy()
        self.create_page()

        col = 280

        if len(data) == 0:
            tk.Label(self.page, text='对不起，没有您要找的商品', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=200, y=400, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=10, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=550, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=655, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][3], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=770, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][4], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=900, y=col, anchor='nw')
            tk.Button(self.page, text='购买', font=('幼圆', 11), bg='CornflowerBlue', fg='Moccasin', command=lambda i=data[i][5], j=data[i][6] :self.purchase(i, j)).place(x=1050, y=col-2, anchor='nw')
            col = col + 30

        obj.close_conn()

    def purchase(self, categoryid, categoryname):
        messagebox.showinfo(message='购买成功')
        obj = loginSearch()
        sql = purchase(self.name, categoryname, categoryid)
        obj.conn.autocommit = True
        cursor = obj.conn.cursor()
        cursor.execute(sql)

        new_sql = update_shoes_clothes(categoryid, categoryname)   
        cursor.execute(new_sql)
        obj.conn.commit()
        obj.close_conn()